﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using ARR.Entities;
using ARR.Services.Domain;
using ARR.Entities.Gateways;

namespace ARR.Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ArticlesService" in both code and config file together.
    public class ArticlesService : IArticlesService
    {
        public void UpdateStatus(int rangeReviewId)
        {
            ArticlesDomain.UpdateStatus(rangeReviewId);
        }

        //Articles
        public List<Article> GetAll(int rangeReviewId, int? categoryId, bool lazyLoad)
        {
            if (lazyLoad)
            {
                return ArticlesDomain.GetAll(rangeReviewId, categoryId);
            }
            else
            {
                return ArticlesDomain.GetAllComplete(rangeReviewId, categoryId);
            }
        }

        public List<Article> GetByCategory(int rangeReviewId, int? categoryId, bool lazyLoad)
        {
            if (lazyLoad)
            {
                return ArticlesDomain.GetAll(rangeReviewId, categoryId);
            }
            else
            {
                return ArticlesDomain.GetAllComplete(rangeReviewId, categoryId);
            }
        }

        public List<Article> SearchArticles(string criteria, int rangeReviewId)
        {
            return ArticlesDomain.SearchArticles(criteria, rangeReviewId);
        }

        public void Join(int[] articleIds, int targetArticleId)
        {
            ArticlesDomain.Join(articleIds, targetArticleId);
        }

        public void Split(int sourceArticleId, List<Article> articles)
        {
            ArticlesDomain.Split(sourceArticleId, articles);
        }

        public Article GetByID(int articleID)
        {
            return ArticlesDomain.GetByID(articleID);
        }

        public List<TempArticle> GetTempArticlesByIds(IEnumerable<int> listIds)
        {
            return ArticlesDomain.GetTempArticlesByIds(listIds);
        }

        public void SaveTempArticles(List<TempArticle> tempArticles)
        {
            ArticlesDomain.SaveTempArticles(tempArticles);
        }

        public void SaveArticles(List<Article> articles)
        {
            ArticlesDomain.SaveArticles(articles);
        }

        public void DeleteTempArticles(List<TempArticle> tempArticles)
        {
            ArticlesDomain.DeleteTempArticles(tempArticles);
        }

        public void UpdateTempArticlesWithCategoryMatch(int categoryId, string[] originalCategories)
        {
            ArticlesDomain.UpdateTempArticlesWithCategoryMatch(categoryId, originalCategories);
        }

        public List<TempArticle> GetSameStoreArticles(int sameStoreId)
        {
            return ArticlesDomain.GetSameStoreArticles(sameStoreId);
        }


        //ArticleSales
        public void UpdateTempArticleSalesArticleIds(int rangeReviewId)
        {
            ArticlesDomain.UpdateTempArticleSalesArticleIds(rangeReviewId);
        }

        public void SaveTempArticleSales(List<TempArticle> tempArticles)
        {
            ArticlesDomain.CombineRepeatedNamesAndUpdateSales(tempArticles);
        }

        public List<TempArticleSale> GetTempArticleSalesByIds(IEnumerable<int> listIds)
        {
            return ArticlesDomain.GetTempArticleSalesByIds(listIds);
        }

        public List<TempArticleSale> GetTempArticleSalesDuplicates()
        {
            return ArticlesDomain.GetTempArticleSalesDuplicates();
        }

        public List<ArticleSale> GetAllSales(int rangeReviewId, int? categoryId = null)
        {
            return ArticlesDomain.GetAllSales(rangeReviewId, categoryId);
        }

        public void SaveSales(List<ArticleSale> sales)
        {
            ArticlesDomain.SaveSales(sales);
        }

        public List<CategoryMargin> GetArticleSalesCategoryMargins(int rangeReviewId)
        {
            return ArticlesDomain.GetCategoryMargins(rangeReviewId);
        }

        public List<TempPIDifference> GetTempPIDifferencesByIds(IEnumerable<int> listIds)
        {
            return ArticlesDomain.GetTempPIDifferencesByIds(listIds);
        }

        public List<TempPIDifference> GetTempPIDifferencesDuplicates()
        {
            return ArticlesDomain.GetTempPIDifferencesDuplicates();
        }

        public void SaveTempPIDifferences(List<TempPIDifference> diffs)
        {
            ArticlesDomain.SaveTempPIDifferences(diffs);
        }
    }
}
